﻿using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Derbster.Domain.Test
{
    [TestClass]
    public class JamUnitTest : ContractUnitTest
    {
        private Match _testMatch;
        [TestInitialize]
        public void TestSetup()
        {
            _testMatch = TestHelper.CreateTestMatch(true, false, "TestMatch");
        }
        [TestMethod]
        public void TestCreateNew()
        {
            
            var newJam = new Jam();
            Assert.IsNotNull(newJam);
        }

        [TestMethod]
        public void TestCreateBadPeriod()
        {
            bool throws = false;
            try
            {
                var newJam = new Jam(_testMatch, 3, 1, 1);
            }
            catch (Exception)
            {
                throws = true;
            }
            Assert.IsTrue(throws);
        }

        [TestMethod]
        public void TestCreateBadNumber()
        {
            bool throws = false;
            try
            {
                var newJam = new Jam(_testMatch, 1, -1, 1);
            }
            catch (Exception)
            {
                throws = true;
            }
            Assert.IsTrue(throws);
        }

        [TestMethod]
        public void TestCreateNewBadLineup()
        {
            var newJam = new Jam();  
            var skater = _testMatch.FirstTeamRoster.Skip(2).First();
            newJam.FirstTeamLineup = new Lineup();
            newJam.SecondTeamLineup = new Lineup();
            newJam.FirstTeamScoring = new Scoring();
            newJam.SecondTeamScoring = new Scoring();
            newJam.FirstTeamLineup.Blockers = new HashSet<Player>();
            newJam.FirstTeamLineup.Blockers.Add(skater);
            newJam.FirstTeamLineup.Jammer = skater;
            Assert.IsFalse(newJam.VerifyJam());
        }

        [TestMethod]
        public void TestCreateNewBadScoring()
        {
            var newJam = new Jam();
            newJam.FirstTeamLineup = new Lineup(newJam);
            newJam.FirstTeamLineup.Blockers = new HashSet<Player>();
            newJam.FirstTeamLineup.AddBlocker(_testMatch.FirstTeamRoster.Players.First());
            newJam.SecondTeamLineup = new Lineup(newJam);
            newJam.SecondTeamLineup.Blockers = new HashSet<Player>();
            newJam.SecondTeamLineup.AddBlocker(_testMatch.SecondTeamRoster.Players.First());
            newJam.FirstTeamScoring = new Scoring(newJam);
            newJam.SecondTeamScoring = new Scoring(newJam);
            newJam.FirstTeamScoring.Passes = new HashSet<ScoringPass>();
            newJam.FirstTeamScoring.Passes.Add(new ScoringPass(newJam.FirstTeamScoring, 1, 1));
            newJam.FirstTeamScoring.Passes.Add(new ScoringPass(newJam.FirstTeamScoring, 1, 4));
            Assert.IsFalse(newJam.VerifyJam());
        }
    }
}
